package com.inspiration.config;

import com.inspiration.utils.PathUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @Description
 * @Author Vincent.jiao
 * @Date 2023/11/16 17:27
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 静态资源处理
     **/
    @SneakyThrows
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){


        File file = new File(PathUtils.getLocalhostRoot() + "/uploadfile/");
        if (!file.exists()) {
            file.mkdirs();
        }
        System.out.println("静态资源处理：" + PathUtils.getLocalhostRoot() + "/uploadfile/");
//appConfig.getResPhysicalPath() 这表示项目所在的文件夹，下面会有介绍
        registry.addResourceHandler("/uploadfile/**").addResourceLocations("file:" + PathUtils.getLocalhostRoot() + "uploadfile/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
